package kmp;

//暴力匹配
public class ViolenceMath {
    public static void main(String[] args) {
        String s1 = "llo1789";
        String s2 = "789";
        System.out.println(violenceMath(s1, s2));
    }

    //暴力匹配算法实现
    public static int violenceMath(String str1, String str2) {
        char[] s1 = str1.toCharArray();
        char[] s2 = str2.toCharArray();
        int s1Lenth = s1.length;
        int s2Lenth = s2.length;

        int i = 0;
        int j = 0;

        while (i < s1Lenth && j < s2Lenth) {
            if (s1[i] == s2[j]) {
                i++;
                j++;
            } else {
                j = 0;
                i = i - j + 1;
            }
        }
        if (j == s2Lenth) {
            return i - j;
        }else {
            return -1;
        }

    }
}
